﻿<%@ Page Title="product" Language="C#" MasterPageFile="~/EasyUI.master" AutoEventWireup="true" CodeBehind="List.aspx.cs" Inherits="jnxc.Web.product.List" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="../ckeditor/ckeditor.js"></script>
    <script src="../ckeditor/adapters/jquery.js"></script>   
    <script src="../Script/upimg.js"></script>
    <script type="text/javascript">
        $(function () {
            InitGird();
            InitSearch();
            InitTree();
            var img = $('#hfimg').val();
            if (img != "") {
                $('#preview').attr("src", img);
            }
        });
        function CKupdate() {
            for (instance in CKEDITOR.instances)
                CKEDITOR.instances[instance].updateElement();
        }
        function InitTree() {
            $('#cid').combotree({
                url: '../controlinfo/GetControl.ashx', //请求数据的页面               
                lines: true,
                method: 'post',
                width:'200',
                queryParams: { "action": "query" }                
            });
            }
            function testchk() {
                var hid = $('#hfcid').val();
                if (hid != "") {
                    return true;

                }
                else {
                    $.messager.alert("提示", "请选择一个防治技术！", "info");
                    return false;
                }

            }
        //初始化表格
        function InitGird() {
            $('#tt').datagrid({
                title: '产品列表', //表格标题
                url: 'GetPro.ashx', //请求数据的页面
                sortName: 'pname', //排序字段
                idField: 'pid', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度
                //height: $(parent.document).find("#mainPanle").height() - 35 > 0 ? $(parent.document).find("#mainPanle").height() - 35 : 500, //高度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                method: 'post',
                columns: [[
                    { field: 'ckb', checkbox: true },
	                { title: '产品名', field: 'pname', width: 150, sortable: true },
                    { title: '防治类别', field: 'cname', width: 150, sortable: true },                   
                    {
                        title: '操作', field: 'pid', width: 80, formatter: function (value, row, index) {                           
                                return '&nbsp;<a style="color:red" href="javascript:" onclick="$(this).parent().click();removeUser();return false;">删除</a>';
                           
                        }
                    }
                ]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "query" },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true //行号
            });


        }
        //初始化搜索框
        function InitSearch() {
            $("#ipt_search").searchbox({
                width: 200,
                //iconCls: 'icon-save',
                searcher: function (val, name) {
                    $('#tt').datagrid('options').queryParams.search_type = name;
                    $('#tt').datagrid('options').queryParams.search_value = val;
                    $('#tt').datagrid('reload');
                },
                prompt: '请输入查询信息'
            });
            $('#pcontent').ckeditor();
            $('#ppara').ckeditor();
        }
        function newUser() {
            //清空内容  
            $('#fm').form('clear');
            for (instance in CKEDITOR.instances)
                CKEDITOR.instances[instance].setData("");
            $('#dlg').dialog('open').dialog('setTitle', '增加产品');
            document.getElementById("test").value = "add";
        }
        function editUser() {

            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要修改的行！", "info");
            }
            if (row) {
                $('#dlg').dialog('open').dialog('setTitle', '修改产品');
                $('#preview').attr('src', row.ppic);
                $('#htpic').val(row.ppic);
                $('#pid').val(row.pid);
                document.getElementById("test").value = "modify";
                $('#fm').form('load', row);
                var result = $.ajax({
                    url: "GetPro.ashx?action=getinfo&pid=" + row.pid,
                    type: 'post',
                    dataType: 'json',
                    async: false,
                    cache: false
                }).responseText;
                result = eval('(' + result + ')');
                var psinfo = result[0].psinfo;
                
                $('#pcontent').val(psinfo);
                var ppara = result[0].ppara;

                $('#ppara').val(psinfo);

            }
        }
        function saveUser() {
            var test = document.getElementById("test").value;
            CKupdate();
            var f = $('#fm');
            if (test == "add") {
                f.form('submit', {
                    url: "GetPro.ashx?action=" + test,
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (result) {
                        if (result.indexOf("T") == 0) {
                            $('#dlg').dialog('close');
                            $.messager.alert("提示", "恭喜您，信息添加成功", "info");
                            $('#tt').datagrid('reload');
                        }
                        else if ((result.indexOf("F") == 0)) {
                            $.messager.alert("提示", "添加失败，请重新操作！", "info");
                            return;
                        }
                        else if ((result.indexOf("L") == 0)) {
                            $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                            top.location = '/index.aspx';
                            return;
                        }
                    }
                });

            } else {

                $('#fm').form('submit', {
                    url: "GetPro.ashx?action=" + test,
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (result) {
                        if (result.indexOf("T") == 0) {
                            $('#dlg').dialog('close');
                            $('#tt').datagrid('clearSelections');
                            $.messager.alert("提示", "恭喜您，信息修改成功", "info");
                            $('#tt').datagrid('reload');

                        }
                        else if ((result.indexOf("F") == 0)) {
                            $.messager.alert("提示", "添加失败，请重新操作！", "info");
                            return;
                        }
                        else if ((result.indexOf("L") == 0)) {
                            $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                            top.location = '/index.aspx';
                            return;
                        }
                    }
                });
            }
        }


        function removeUser() {
            var test = document.getElementById("test").value = "delete";
            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要删除的行！", "info");
            }
            if (row) {
                $.messager.confirm('提示', '你确定要删除这条信息吗？', function (r) {
                    if (r) {
                        $('#fm').form('submit', {
                            url: 'GetPro.ashx?pid=' + row.pid + "&action=" + test,
                            onSubmit: function () {
                                //return $(this).form('validate');  
                            },
                            success: function (result) {
                                if (result.indexOf("T") == 0) {
                                    $('#dlg').dialog('close');
                                    $('#tt').datagrid('clearSelections'); //清空选中的行  
                                    $.messager.alert("提示", "恭喜您，信息删除成功！", "info");                                   
                                    $('#tt').datagrid('reload');
                                }
                                else {
                                    $.messager.alert("提示", "添加失败，请重新操作！", "info");
                                    return;
                                }

                            }

                        });
                    }
                })
            }
        }

    </script>
    <style>
        #showpro td {
         padding-top:5px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table id="tt">
    </table>
    
    <div id="tab_toolbar" style="padding: 4px;">
        <table cellpadding="0" cellspacing="0" style="width: 100%">
            <tr>

                <td style="padding-left: 2px">

                    
                    <a href="#" id="a_add" onclick="newUser();"
                        class="easyui-linkbutton" iconcls="icon-add">添加</a>
                    <a href="javascript:void(0)" onclick="editUser() " class="easyui-linkbutton" data-options="iconCls:'icon-edit'">修改</a>
                    <a href="#" onclick="removeUser();return false;" id="a_del" class="easyui-linkbutton" iconcls="icon-cancel">删除</a>

                </td>
                <td style="text-align: right; padding-right: 15px">
                    <input id="ipt_search" menu="#search_menu" />
                    <div id="search_menu" style="width: 120px">
                        <div name="usernum">
                            产品名
                        </div>                        
                    </div>
                </td>
            </tr>
        </table>
    </div>   
    <div id="dlg" class="easyui-dialog" style="width: 800px; height:500px; padding: 5px; overflow:auto;"
        data-options="closed:true,buttons:'#dlg-buttons',shadow:false">      
        
        <form id="fm" method="post" enctype="multipart/form-data" action="GetPro.ashx" >                
                <input name="Test" id="test" type="hidden" /> 
            <input name="pid" id="pid" type="hidden" />              
           <table style="width: 100%;" cellpadding="2" cellspacing="1" class="border">
        <tr>
            <td class="tdbg">
                
<table cellSpacing="0" cellPadding="0" width="100%" border="0" id="showpro">
    <tr>
        <td>防治技术</td>
        <td><input id="cid" name="cid"/></td>
    </tr>
	<tr>	
	<td   align="right">
		名称
	：</td>
	<td  width="*" align="left">
		<input id="pname" name="pname" class="easyui-validatebox" data-options="required:true"></input>
	</td></tr>
	<tr>
	<td   align="right">
		参数
	：</td>
	<td  width="*" align="left">
        <textarea class="easyui-validatebox" id="ppara" name="ppara" ></textarea>		
	</td></tr>
	<tr>
	<td  align="right">
		简介
	：</td>
	<td  width="*" align="left">
        <textarea class="easyui-validatebox" id="pcontent" name="pcontent" ></textarea>
		
	</td></tr>	
	<tr>
	<td  align="right">
		图片
	：</td>
	<td height="25" width="*" align="left">
        <input id="ppic" name="ppic"  type="file" onchange="javascript:setImagePreview(this,localImag,preview);" />
        <input name="htpic" id="htpic" type="hidden" /> 
	</td></tr>
	<tr>
	<td  align="right">
    预览:</td>
	<td height="25" width="*" align="left">
         <div id="localImag"  style="height:80px">  
       <img id="preview" alt="预览图片" onclick="over(preview,divImage,imgbig);" src="../teampics/user.jpg" style="width: 100px; height: 80px;"/>
             </div>
             </td></tr>
</table>
                

            </td>
        </tr>
       
    </table>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveUser()">保存</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlg').dialog('close')">关闭</a>
    </div>
</asp:Content>

